home *** CD-ROM | disk | FTP | other *** search
/ The Game Master (3rd Edition) / The Game Master 3rd edition.iso / files / demo_vga / julia / julia.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1985-04-04  |  23.0 KB  |  531 lines

  1. 100  DEFINT A-Z
  2. 110  KEY OFF
  3. 130  DIM PARAM(10)    'parameters for machine language subroutine juline.bin
  4. 140  DIM SCRSTR(42)   'space for output of a screen line from juline
  5. 150  DIM CODE(90)     'juline loaded here
  6. 160  DIM BUF!(4090)   'buffer for bloading and bsaving picture and parameters
  7. 170                   ' parameters start at buf!(4001), comment at startcom
  8. 180  STARTTEXT = 4020  'index in buf! where comment length is
  9. 190  CANSAVE=0   'flag to check if buf! is filled with consistent information
  10. 200  BIG!=2^15   'scale factor for data conversion for juline
  11. 205  MINWIDTH! = 319*2^(-14)   'minimum picture width
  12. 210  PAL = 0   ' initial pallette
  13. 212  COLR = 0  'graphics backround color
  14. 215  SCREEN 1,0 : COLOR COLR,PAL   'test on color machine?
  15. 220  GOSUB 3050  'setup for box mode
  16. 230  A!=0.75 :B! = 0:GOSUB 840         'default parameters for the start
  17. 240  MK=20: C2=15 : C1 = 10 : GOSUB 940  'three subroutines to convert parameters
  18. 250  XL!=-1.6 : XH! = 1.6 : GOSUB 1080
  19. 260  YL! = -0.999 : YH!= 0.999 : GOSUB 1210
  20. 270  A$="o" : GOTO 520 ' start with overview
  21. 500    ' main command control loop follows
  22. 510  A$ = INKEY$ : IF A$="" THEN 510
  23. 515   'entry point after routines that terminate by reading next command char
  24. 520  IF A$="n" THEN GOSUB 800: GOSUB 920 : GOSUB 1060 : GOSUB 1190 : GOSUB 1300 : GOTO 510     'all new parameters then calc picture
  25. 530  IF A$="p" THEN GOSUB 1500 : GOTO 510    'display parameters
  26. 540  IF A$="j" THEN GOSUB 1580 : GOTO 510  'see picture for current param
  27. 550  IF A$="s" THEN GOSUB 1840 : GOTO 510    'save picture and param
  28. 555  IF A$="b" THEN GOSUB 3250 : GOTO 510    'switch to box mode
  29. 560  IF A$="c" THEN CLS : GOTO 510    'clear screen
  30. 570  IF A$="h" THEN GOSUB 1620 : GOTO 520    'see help menu (and get next key)
  31. 580  IF A$="f" THEN GOSUB 800 : GOTO 510    'change function params
  32. 585  IF A$="m" THEN GOSUB 2300: GOTO 510    'shift iteration params together
  33. 590  IF A$="i" THEN GOSUB 920 : GOTO 510    'change iteration params sepatately
  34. 600  IF A$="x" THEN GOSUB 1060 : GOTO 510    'change x coord of window
  35. 610  IF A$="y" THEN GOSUB 1190 : GOTO 510    'change y coord of window
  36. 620  IF A$="w" THEN GOSUB 1060 :GOSUB 1190 : GOTO 510    'change window
  37. 630  IF A$="q" THEN WIDTH 80 : SCREEN 0,0 :END
  38. 640  IF A$="l" THEN GOSUB 1950 : GOTO 510    'load picture
  39. 650  DIG=ASC(A$)-ASC("0") :IF (0<=DIG)AND (DIG <=9) THEN COLR= DIG : COLOR COLR, PAL: GOTO 510    'change backround color
  40. 660  IF A$="-" THEN PAL = 1- PAL :COLOR ,PAL: GOTO 510    'switch pallette
  41. 670  IF A$="e" THEN GOSUB 2100 : GOTO 510    'edit text
  42. 680  IF A$="t" THEN LOCATE 6,1 : PRINT M$ : GOTO 510    'display text
  43. 685  IF A$="o" THEN GOSUB 5000 : GOTO 530    'overview + next key
  44. 690  PRINT CHR$(7);
  45. 700  GOTO 510
  46. 710    'initialize for pic calc
  47. 720  DEF SEG
  48. 730  BLOAD"juline.bin",VARPTR(CODE(0))
  49. 740  ADDR =0
  50. 750  GET (0,0)-(319,0),SCRSTR  'JUST FOR SIZE DATA at beginning
  51. 760  CLS
  52. 770  RETURN
  53. 780  ' end of initialize for pic calc
  54. 785  '
  55. 790  ' start of get julia set parameters
  56. 800  PRINT " Enter Re(L), Im(L)
  57. 810  PRINT "   0 <= Re(L) < 2, 0 <= Im(L) < 1  "
  58. 820  INPUT "",A!,B!
  59. 830   'entry point for default values
  60. 840  IF (A! < 0) OR (A! >= 2) OR (B! < 0) OR (B! >= 1) THEN PRINT CH$(7): GOTO 800
  61. 850  PARAM(3) = A!*2^14
  62. 860  PARAM(4) = B!*2^12
  63. 870  A! = PARAM(3)/2^14
  64. 875  B! = PARAM(4)/2^12
  65. 880  BUF!(4001) = A!
  66. 885  BUF!(4002) = B!
  67. 890  CANSAVE=0
  68. 900  RETURN   ' from getting julia parameters
  69. 905  '
  70. 910  ' start get iterations
  71. 920  INPUT "three iteration limits, largest first:      ",MK, C2, C1
  72. 930    'entry point for default values
  73. 940  IF (C2 > MK) OR (C1 > MK) THEN PRINT "Max iterations must be largest." : GOTO 920
  74. 950  IF C1 > C2 THEN TEMP = C1 : C1 = C2 : C2 = TEMP
  75. 960  BUF!(4003) = MK
  76. 970  PARAM(5) = MK
  77. 980  BUF!(4004) = C2
  78. 990  PARAM(7) = MK-C2
  79. 1000  BUF!(4005) = C1
  80. 1010  PARAM(6) = MK-C1
  81. 1020  CANSAVE=0
  82. 1030  RETURN
  83. 1040    ' from get iterations
  84. 1045  '
  85. 1050    ' start get window
  86. 1060  INPUT "Enter low and high x (both less than 2 in magnitude)  ",XL!, XH!
  87. 1070    'entry for default values
  88. 1080  IF XL! > XH! THEN T! = XL! : XL! = XH! : XH! = T!
  89. 1090  IF (XL! <= -2) OR (XH! >= 2) THEN PRINT "Magnitude too high.  " : GOTO 1060
  90. 1100  DX! =(XH!-XL!)/319
  91. 1110  PARAM(2) = DX!*2^14    'SCALED DELX
  92. 1112  IF PARAM(2) = 0 THEN PRINT"**TOO CLOSE TOGETHER**" : GOTO 1060
  93. 1115  DX! = PARAM(2) / 2^14    'SCALED DELX
  94. 1120  XL = XL!*2^14   ' SCALED LOW X
  95. 1125  XL! = XL/2^14
  96. 1127  XH! = XL! + DX!*319
  97. 1130  BUF!(4006) = XL!
  98. 1135  BUF!(4007) = XH!
  99. 1140  XL = XL!*2^14   ' SCALED LOW X
  100. 1150  CANSAVE=0
  101. 1160  RETURN
  102. 1170     ' from x coord
  103. 1175  '
  104. 1180     ' start y coord
  105. 1190  INPUT "low and high y (Only magnitude less than 1 plotted)  ",YL!, YH!
  106. 1200     ' entry for default values
  107. 1210  IF YL! > YH! THEN T! = YL! : YL! = YH! : YH! = T!
  108. 1220  BUF!(4008) = YL!
  109. 1230  BUF!(4009) = YH!
  110. 1240  DY! =(YH!-YL!)/199
  111. 1250  YLSC! = YL!*BIG! : DY! = DY!*BIG!
  112. 1260  CANSAVE=0
  113. 1270  RETURN
  114. 1280   'from get y coord of window
  115. 1285  '
  116. 1290  'calculate picture with already given parameters
  117. 1300  Y!=YLSC!
  118. 1310  CLS
  119. 1320  IF CODE(0)=0 THEN GOSUB 720   ' initialize for first pic calc
  120. 1330  FOR J = 199 TO 0 STEP -1
  121. 1340  IF ABS(Y!) >= BIG!-1 THEN 1420
  122. 1350  PARAM(0) = XL
  123. 1360  PARAM(1) = Y!
  124. 1370  PARAM(8) = 80
  125. 1380  ADDR = VARPTR(CODE(0))
  126. 1390  DEF SEG
  127. 1400  CALL ADDR ( SCRSTR(2), PARAM(0))
  128. 1410  PUT (0,J), SCRSTR, PSET
  129. 1420  Y! = Y! +DY! : NEXT J
  130. 1430  GET (0,0)-(319,199),BUF!
  131. 1440  CANSAVE=-1   'new parameters have been used to generate pic - can save
  132. 1442  RETURN 'from recalculation julia set
  133. 1445  '
  134. 1449   ' start labeling of julia set
  135. 1450  LOCATE 1,1
  136. 1460  PRINT "Re:";A!;" Im:";B!
  137. 1470  RETURN
  138. 1480    ' from labeling pic
  139. 1485  '
  140. 1490    'display parameters
  141. 1500  LOCATE 1,1
  142. 1510  PRINT "Re:";A!;"Im:";B!
  143. 1520  PRINT "Iter:";MK;C2;C1
  144. 1530  PRINT "Re limits:";XL!;XH!
  145. 1540  PRINT "Im limits:";YL!;YH!
  146. 1550  RETURN
  147. 1560     'end of parameter display
  148. 1565  '
  149. 1570     'display julia set
  150. 1580  IF CANSAVE THEN PUT (0,0),BUF!,PSET ELSE GOSUB 1300 : GOSUB 1450
  151. 1590  RETURN
  152. 1600     'end display julia set
  153. 1605  '
  154. 1610   'help display
  155. 1620  SCREEN 0,0:WIDTH 80: COLOR 2,0
  156. 1625  PRINT "     HELP SCREEN FOR JULIA SET CALCULATION
  157. 1630  PRINT
  158. 1640  PRINT "KEY ACTION
  159. 1645  PRINT "b   switch to box mode -- set new window parameters graphically
  160. 1650  PRINT "c   clear screen
  161. 1660  PRINT "e   edit text saved with picture
  162. 1670  PRINT "f   change function parameters (change julia set)
  163. 1680  PRINT "h   display this help screen (there is also a help screen in box mode)
  164. 1690  PRINT "i   change each iteration parameter separately
  165. 1700  PRINT "j   display julia set with current parameters
  166. 1710  PRINT "l   load picture and parameters from disk
  167. 1715  PRINT "m   enter new maximum for iterations and shift other two by the same amount
  168. 1720  PRINT "n   enter all new parameters and then see new julia set
  169. 1725  PRINT "o   display an overview of the program
  170. 1730  PRINT "p   display current parameters
  171. 1740  PRINT "s   save picture and parameters to disk
  172. 1750  PRINT "t   display text saved with picture
  173. 1760  PRINT "w   change all window parameters numerically (press b to do it graphically)
  174. 1770  PRINT "x   change x coord of window
  175. 1780  PRINT "y   change y coord of window
  176. 1790  PRINT "-   switch pallette
  177. 1800  PRINT "0 to 9  new backround color
  178. 1802  PRINT:PRINT "ENTER NEXT COMMAND.";
  179. 1803  A$=INKEY$ : IF A$="" THEN 1803
  180. 1805  SCREEN 1,0 : COLOR COLR, PAL
  181. 1810  RETURN
  182. 1820    'end of help screen
  183. 1825  '
  184. 1830     ' start save pic
  185. 1840  IF NOT CANSAVE THEN GOSUB 1300
  186. 1850  BUF!(STARTTEXT) = LEN(M$)
  187. 1860  DEF SEG
  188. 1870  FOR I = 1 TO LEN(M$)
  189. 1880  POKE VARPTR(BUF!(STARTTEXT+1)) -1 +I,ASC(MID$(M$,I,1))
  190. 1890  NEXT I
  191. 1900  INPUT "file name: ",N$
  192. 1910  DEF SEG :BSAVE N$,VARPTR(BUF!(0)),4*STARTTEXT +260
  193. 1920  RETURN
  194. 1930    'end of save pic
  195. 1940   'load pic and param
  196. 1950  INPUT "Name of file to load: ",N$
  197. 1960  DEF SEG :BLOAD N$,VARPTR(BUF!(0))
  198. 1970  PUT (0,0),BUF!,PSET
  199. 1980  CANSAVE=-1
  200. 1990  A!=BUF!(4001):B! = BUF!(4002):GOSUB 840         'loaded parameters
  201. 2000  MK=BUF!(4003): C2 =BUF!(4004) : C1 = BUF!(4005) : GOSUB 940
  202. 2010  XL!=BUF!(4006) : XH! = BUF!(4007) : GOSUB 1080
  203. 2020  YL! = BUF!(4008) : YH!= BUF!(4009) : GOSUB 1210
  204. 2030  M$ =SPACE$(BUF!(STARTTEXT))
  205. 2040  FOR I = 1 TO LEN(M$)
  206. 2050  MID$(M$,I,1) = CHR$(PEEK(VARPTR(BUF!(STARTTEXT+1)) -1 +I))
  207. 2060  NEXT I
  208. 2070  RETURN
  209. 2080    'end of load pic and param
  210. 2085  '
  211. 2090   'start edit text
  212. 2100  CLS :LOCATE 1,1 : PRINT "Edit your message
  213. 2120  PRINT "  Press the END key
  214. 2130  PRINT "and THEN press return when done.
  215. 2140  LOCATE 6,1: PRINT M$
  216. 2150  LOCATE 6,1: LINE INPUT"",N$
  217. 2160  LOCATE 11,1: PRINT " you changed it to:
  218. 2170  LOCATE 13,1:PRINT N$
  219. 2180  PRINT
  220. 2190  PRINT "ok? (y/n) "
  221. 2200  A$=INKEY$ : IF A$="" THEN 2200
  222. 2210  IF A$="y" THEN M$=N$ : PRINT : PRINT "Go on." :RETURN
  223. 2220  GOTO 2100
  224. 2230    'end of edit message
  225. 2235  '
  226. 2299   ' change max iterations and shift others
  227. 2300  INPUT "just the maximum for iterations: ",MKN
  228. 2310  C1 = C1 + MKN-MK  'shift other two limits
  229. 2320  C2 = C2 + MKN-MK  'shift other two limits
  230. 2330  MK = MKN
  231. 2340  GOTO 940  'finish as when changing all iteration limits
  232. 2350   '
  233. 3040    ' set variables for future box mode (once)
  234. 3050  DIM V!(3)    'vertex screen coord 0,1 - x,  2,3 - y
  235. 3055  DIM V(3)    'rounded integer version of v!
  236. 3060  V!(0)=144 : V!(1) = 176 : V!(2) = 90 : V!(3) = 110
  237. 3070  DIM DV!(3)   'proposed change to low, high limit on coord
  238. 3080  DIM NV!(3)   'proposed next low, high coord
  239. 3090  DIM BV(3)   'max coord
  240. 3100  BV(0) = 319  : BV(2) = 199
  241. 3105  DIM MINPIX!(2) 'min box dimensions (use component 0 and 2)
  242. 3107  MINPIX!(2) = 1
  243. 3110  DIM DEL!(3)  ' size of jump
  244. 3120  DEL!(0) = 16 : DEL!(1) = 16 : DEL!(2) =  0 : DEL!(3) =  0
  245. 3130       ' del!(1) > 0, del!(0) is pos for center move, neg for size change
  246. 3132       ' del!(2), del!(3) > 0 if relate dimension changes by factor f!
  247. 3135  F! =319/199  'factor relating width to height in r mode
  248. 3140  BD = 30  ' loops before blinking
  249. 3145  SEENBOXHELP = 0   'flag to show help menu first time
  250. 3150  DIM HS(81),VS(201)    'hold horozontal and vert line data for putting
  251. 3160  DEF FNX!(I) =XL! +(XH!-XL!)*I/319  ' screen to world coord conversion -- x
  252. 3165  DEF FNY!(I) =YH! -(YH!-YL!)*I/199  'screen to world coord conversion -- y
  253. 3170  LINE (0,0)-(319,0)
  254. 3180  GET (0,0)-(319,0),HS
  255. 3190  LINE (0,0)-(0,199)
  256. 3200  GET (0,0)-(0,199),VS
  257. 3210  CLS
  258. 3220  SEE=0  'flag for visibility of box
  259. 3230  GOSUB 3980  'init box dim
  260. 3240  RETURN   ' from set up future box mode
  261. 3245  '
  262. 3250  'start main input and blink loop in box mode
  263. 3255  MINPIX!(0) = MINWIDTH!/DX! + 0.5: IF MINPIX!(0) < 1 THEN MINPIX!(0) = 1
  264. 3256  IF V!(1) - V!(0) < MINPIX!(0) THEN V!(0) = (319-MINPIX!(0))/2 : V!(1) = V!(0) + MINPIX!(0) + 0.000999999: GOSUB 3980  ' if window gets magnified, it can't blow up too far
  265. 3257  IF NOT SEENBOXHELP THEN GOSUB 3720 : GOSUB 4030 : SEENBOXHELP = -1 : GOTO 3280  'start with help screen the first time
  266. 3258  IF CANSAVE THEN PUT (0,0),BUF!,PSET ELSE GOSUB 1300  'make sure picture on screen
  267. 3259  SEE=0 : GOSUB 4030 : A$ ="c" : GOTO 3340  'start in center mode
  268. 3260  GOSUB 4030  'xor box
  269. 3270  A$ = INKEY$ : IF A$ = "" THEN BC = BC+1 : IF BC < BD THEN 3270 ELSE GOTO 3260
  270. 3280  IF LEN(A$) = 1 THEN 3340
  271. 3290  IF RIGHT$(A$,1) =CHR$(72) THEN GOSUB 3430 : GOTO 3260 'up arrow
  272. 3300  IF RIGHT$(A$,1) =CHR$(80) THEN GOSUB 3460 : GOTO 3260 'down arrow
  273. 3310  IF RIGHT$(A$,1) =CHR$(75) THEN GOSUB 3490 : GOTO 3260 'left arrow
  274. 3320  IF RIGHT$(A$,1) =CHR$(77) THEN GOSUB 3520 : GOTO 3260 'right arrow
  275. 3330  PRINT CHR$(7); : GOTO 3260
  276. 3339  ' branch to here when start box mode
  277. 3340  IF A$="c" THEN DEL!(0)=DEL!(1): DEL!(2)=0 : DEL!(3) = 0: GOTO 3260    'move center
  278. 3345  IF A$="r" THEN GOSUB 4300 : GOTO 3260    'change dimensions, relate by f!
  279. 3350  IF A$="s" THEN DEL!(0)=-DEL!(1) : DEL!(2)=0 : DEL!(3) = 0 : GOTO 3260    'change dimensions separately
  280. 3360  IF A$="+" THEN GOSUB 3640 : GOTO 3260     'double jump size
  281. 3370  IF A$="-" THEN GOSUB 3660 : GOTO 3260     'halve jump size
  282. 3375  IF A$="f" THEN GOSUB 4500 : GOTO 3260     'change relation of sides and put in r mode
  283. 3380  IF A$="h" THEN GOSUB 3720 : GOTO 3280    'display help scr + get next key
  284. 3385  IF A$="a" THEN GOSUB 4100 : RETURN 'accept new window, return to main menu
  285. 3390  IF A$="q" THEN GOSUB 3690 : RETURN    'return to main menu
  286. 3395  IF A$="k" THEN GOSUB 4200 : RETURN 'keep box in pict, return to main menu
  287. 3400  IF A$="w" THEN GOSUB 3910 : GOTO 3280    'display window param for box, return with next key
  288. 3410  PRINT CHR$(7); : GOTO 3260
  289. 3420   ' set shifts and coord indices for arrow keys
  290. 3430  IF DEL!(2) < 0 THEN 4600  'r mode
  291. 3435  DV!(0) = -DEL!(1) : DV!(1) = -DEL!(0) 'up arrow-coord reverse
  292. 3440  ISH = 2
  293. 3450  GOTO 3560
  294. 3460  IF DEL!(2) < 0 THEN 4650  ' r mode shrink
  295. 3465  DV!(0) = DEL!(1) : DV!(1) = DEL!(0)     'down arrow-coord reverse
  296. 3470  ISH = 2
  297. 3480  GOTO 3560
  298. 3490  IF DEL!(2) < 0 THEN 4650  ' r mode shrink
  299. 3495  DV!(0) = -DEL!(0) : DV!(1) = -DEL!(1)  'left arrow
  300. 3500  ISH = 0
  301. 3510  GOTO 3560
  302. 3520  IF DEL!(2) < 0 THEN 4600   ' r mode
  303. 3525  DV!(0) = DEL!(0) : DV!(1) = DEL!(1)   'right arrow
  304. 3530  ISH = 0
  305. 3540  GOTO 3560
  306. 3550    ' next is common ending for all arrow keys in c or s mode
  307. 3560  NV!(0) = V!(ISH) + DV!(0) : NV!(1) = V!(ISH+1) + DV!(1)
  308. 3570  IF (NV!(0) < 0) OR (NV!(1) > BV(ISH)) OR (NV!(0) > NV!(1) - MINPIX!(ISH)) THEN PRINT CHR$(7); : RETURN 'off screen or reverse sides or too small
  309. 3580  IF SEE THEN GOSUB 4030   'make sure box off before moving
  310. 3590  V!(ISH) =NV!(0) : V!(ISH+1) = NV!(1)
  311. 3600  GOSUB 3980 'set new dimensions for xor
  312. 3610  RETURN
  313. 3620    'end of all arrow keys in c or s mode
  314. 3630   'double jump size
  315. 3640  IF DEL!(1) < 64  THEN DEL!(0) = 2*DEL!(0) : DEL!(1) = 2*DEL!(1) : DEL!(2) = 2*DEL!(2) : DEL!(3) = 2*DEL!(3) ELSE PRINT CHR$(7);
  316. 3650  RETURN   ' end double jump size
  317. 3660  IF DEL!(1) >= 2 THEN DEL!(0) = DEL!(0)/2 : DEL!(1) = DEL!(1)/2 : DEL!(2) = DEL!(2)/2 : DEL!(3) = DEL!(3)/2 ELSE PRINT CHR$(7);
  318. 3670  RETURN   ' end halve jump size
  319. 3680   'remove box if there
  320. 3690  IF SEE = 1 THEN GOSUB 4030
  321. 3700  RETURN   ' from remove box if there
  322. 3710   'display help screen
  323. 3720  SCREEN 0,0 : WIDTH 80 : COLOR 2,0
  324. 3730  PRINT "Help screen for Box mode (choosing next window parameters graphically)": PRINT
  325. 3740  PRINT"KEY           ACTION
  326. 3750  PRINT"arrow keys    change blinking box
  327. 3760  PRINT"+    double size of changes caused by arrows
  328. 3770  PRINT"-    halve size of changes caused by arrows
  329. 3780  PRINT"a    Accept new window parameters matching box and return to main menu
  330. 3790  PRINT"c    Make arrow keys move the center of the box (not change size)
  331. 3795  PRINT"f    set factor relating width to height when r is pressed
  332. 3800  PRINT"h    Display this help screen
  333. 3810  PRINT"k    Put the box in the picture and leave box mode (do not change window)
  334. 3820  PRINT"q    Quit and return to main menu WITHOUT changing window parameters
  335. 3825  PRINT"r    Make arrow keys relate changes in width and height by factor f, fix center
  336. 3830  PRINT"s    Make arrow keys separately affect width and height of box and fix center
  337. 3840  PRINT"w    Display window parameters for the current box
  338. 3850  PRINT:PRINT "PRESS SPACE BAR OR ENTER NEXT COMMAND.";
  339. 3860  A$=INKEY$ : IF A$="" THEN 3860
  340. 3880  SEE=0
  341. 3890  SCREEN 1,0 : COLOR COLR, PAL
  342. 3893  IF CANSAVE THEN PUT (0,0),BUF!,PSET ELSE GOSUB 1300
  343. 3896  RETURN 'from box help menu
  344. 3900   'display window param for box
  345. 3910  CLS
  346. 3920  PRINT "Window parameters for current box:
  347. 3925  PRINT "Re limits:";FNX!(V!(0));FNX!(V!(1))
  348. 3930  PRINT "Im limits:";FNY!(V!(3));FNY!(V!(2))
  349. 3940  PRINT:PRINT:PRINT "ENTER NEXT COMMAND.
  350. 3945  A$ = INKEY$ : IF A$ = "" THEN 3945
  351. 3950  SEE=0 : GOSUB 1580
  352. 3960   RETURN 'from window param display
  353. 3970   'set box dimensions
  354. 3980  FOR I = 0 TO 3 : V(I) = V!(I) : NEXT I  'want integers
  355. 3985  HS(0) = 2*(V(1)-V(0)) + 2  'number of bits wide for box -- 2 per pixel
  356. 3990  VS(1) = V(3)-V(2)-1  ' pixels in side -- excluding corners
  357. 4000  RETURN
  358. 4010  ' end of set box dimensions
  359. 4020  'xor box
  360. 4030  SEE = 1-SEE : BC = 0
  361. 4040  PUT (V!(0),V!(2)),HS : PUT (V!(0), V!(2) + 1), VS : PUT (V!(0), V!(3)),HS : PUT (V!(1),V!(2) + 1),VS : RETURN
  362. 4050  'end xor box
  363. 4099  'start accept new box parameters
  364. 4100  T! = FNX!(V!(0))
  365. 4110  XH! = FNX!(V!(1))
  366. 4120  XL! = T!
  367. 4130  GOSUB 1080   'record new x-coord
  368. 4150  T! = FNY!(V!(2))
  369. 4160  YH! = FNY!(V!(3))
  370. 4170  YL! = T!
  371. 4180  GOSUB 1210  'record new y -- coord
  372. 4190  GOSUB 1500 : RETURN    'from accepting new box parameters
  373. 4195  '
  374. 4199  'start keep box in picture and end box mode
  375. 4200  IF SEE =0 THEN GOSUB 4030   'make sure box shows
  376. 4210  GET (0,0)-(319,199),BUF!
  377. 4230  RETURN    'from keeping box
  378. 4298  '
  379. 4299  'set up for r mode
  380. 4300  SIF! = (XH!-XL!)*199/((YH!-YL!)*319*F!)
  381. 4305  NV!(2)= (V!(2) + V!(3))/2 - SIF!*(V!(1)-V!(0))/2
  382. 4310  NV!(3)= (V!(2) + V!(3))/2 + SIF!*(V!(1)-V!(0))/2
  383. 4320  IF (NV!(2) < 0) OR (NV!(3) > BV(2)) OR (NV!(2) > NV!(3) - 1) THEN PRINT CHR$(7); : RETURN 'off screen or reverse sides
  384. 4337  IF SEE THEN GOSUB 4030   'make sure box off before moving
  385. 4340  V!(2) = NV!(2) : V!(3) = NV!(3)
  386. 4360  DEL!(0)=-DEL!(1) : DEL!(2)=SIF!*DEL!(0) : DEL!(3) = SIF!*DEL!(1)
  387. 4370  GOSUB 3980 'set new dimensions for xor
  388. 4380  RETURN   ' from enter r mode
  389. 4398  '
  390. 4499  'start enter new f!
  391. 4500  CLS
  392. 4510  PRINT "The factor relating the width of the
  393. 4520  PRINT " box to the height after r is pressed
  394. 4530  PRINT " is ",F!
  395. 4540  PRINT "Enter a new value (return for same)
  396. 4550  INPUT NF!
  397. 4553  IF NF! > 0 THEN F! = NF!
  398. 4560  SEE=0
  399. 4570  GOSUB 1580 :  RETURN 'from set f!
  400. 4580  '
  401. 4599  'start enlarge box in r mode
  402. 4600  FOR I = 0 TO 3 : NV!(I) = V!(I) + DEL!(I) : NEXT I
  403. 4602  IF (NV!(0) < 0) OR (NV!(1) > BV(0))  THEN PRINT CHR$(7); : RETURN 'off screen 
  404. 4605  IF (NV!(2) < 0) OR (NV!(3) > BV(2)) THEN PRINT CHR$(7); : RETURN 'off screen 
  405. 4610  GOTO 4680   'jump to finish with shrink box code
  406. 4620  '
  407. 4649  'START SHRINK BOX IN R MODE
  408. 4650  FOR I = 0 TO 3 : NV!(I) = V!(I) - DEL!(I) : NEXT I
  409. 4655  IF (NV!(0) > NV!(1) - MINPIX!(0)) THEN PRINT CHR$(7); : RETURN 'sides too close
  410. 4680  IF SEE THEN GOSUB 4030   'make sure box off before moving
  411. 4685  FOR I = 0 TO 3 : V!(I) = NV!(I) : NEXT I
  412. 4687  GOSUB 3980 'set new dimensions for xor
  413. 4690  RETURN   ' from changing box size in r mode
  414. 4695  '
  415. 4990  'overview command
  416. 5000  SCREEN 0,0 : WIDTH 80 : COLOR 2,0
  417. 5010  GOSUB 6260
  418. 5020  PRINT"                   Interactive Julia Set Calculation
  419. 5030  PRINT"           by Andy Harrington, Loyola University of Chicago
  420. 5035  PRINT : PRINT"                     AN OVERVIEW OF THE PROGRAM
  421. 5040  PRINT
  422. 5050  PRINT"ALGORITHM AND MATHEMATICAL BACKROUND
  423. 5060  PRINT"     This program uses a fast machine language subroutine with integer 
  424. 5070  PRINT"arithmetic to calculate approximations to Julia sets for complex functions 
  425. 5080  PRINT"                      F(z) = z^2 - L.
  426. 5090  PRINT"     We use the property of any Julia set for a polynomial that there is a 
  427. 5100  PRINT"bounded region K, with the following properties:
  428. 5110  PRINT"1.  The boundary of K is the Julia set.
  429. 5120  PRINT"2.  No matter how many times you iterate F starting from a point in K, you stay";
  430. 5130  PRINT"in K, but if you start your iteration from outside K you are eventually drawn 
  431. 5140  PRINT"off to infinity.
  432. 5150  PRINT"     The program has as a parameter a maximum number of iterations, M.  The 
  433. 5160  PRINT"program approximates K by plotting all screen points whose first M iterates 
  434. 5170  PRINT"stay in the region -2 < x < 2 and -1 < y <1.  With a color monitor you can 
  435. 5180  PRINT"choose three different values of M and superimpose the corresponding pictures
  436. 5190   PRINT"to see how much extra iterations affect the approximation.
  437. 5200  GOSUB 6200 : IF A$ <> " " THEN GOSUB 6230 : RETURN ' from overview
  438. 5210  GOSUB 6260 : PRINT"MAIN COMMAND PROCESSOR
  439. 5220  PRINT"     The program accepts a variety of single keystroke commands.
  440. 5230  PRINT"o   Redisplay this overview.
  441. 5240  PRINT"h   The help menu containing the whole list of commands displayed 
  442. 5250  PRINT"alphabetically.
  443. 5260  PRINT"c   Clear the screen.
  444. 5270  PRINT"p   Displays the parameters for the current picture without erasing first.  
  445. 5280  PRINT"This way you have the opportunity to superimpose this data on your picture 
  446. 5290  PRINT"before photographing.  If you just want to view the parameters, clear the 
  447. 5300  PRINT"screen first.
  448. 5310  PRINT"n   Give ALL parameters new values and then see the associated Julia set.
  449. 5320  PRINT"j   See the Julia set picture for the current parameters.  Press this after you";
  450. 5330  PRINT"have set individual parameters the way you want them.  If you have reentered 
  451. 5340  PRINT"parameters, then the new picture is displayed as it is calculated.  The end of 
  452. 5350  PRINT"the calculation is indicated by the function parameters appearing on the 
  453. 5360  PRINT"screen.  If no parameters have been reentered, so the picture is in memory, 
  454. 5370  PRINT"then it is copied immediately.  The parameters do not appear when the picture 
  455. 5380  PRINT"is copied from memory.
  456. 5390  PRINT"f   Set the function f(z) = z^2 - L by choosing the real and imaginary parts of";
  457. 5400  PRINT"the parameter L.
  458. 5410  PRINT"i   Set all three of the iteration limits discussed above.
  459. 5420  PRINT"m   Reset the maximum of the three iteration limits.  If the largest iteration
  460. 5430  PRINT"limit is changed, then the other two iteration limits are shifted by the same
  461. 5440  PRINT"amount.";
  462. 5450  GOSUB 6200 : IF A$ <> " " THEN GOSUB 6230 : RETURN ' from overview
  463. 5460  GOSUB 6260 : PRINT"SETTING THE SCREEN WINDOW
  464. 5470  PRINT"x   Set the x coordinates of the edges of the screen.
  465. 5480  PRINT"y   Set the y coordinates of the edges of the screen.
  466. 5490  PRINT"w   Set the whole screen window -- both x and y limits.
  467. 5500  PRINT"b   Manipulate a flashing box on the screen to graphically choose a new window 
  468. 5510  PRINT"for a magnification of the current picture.  The command invokes a separate 
  469. 5520  PRINT"command processor, called box mode, described later on.
  470. 5530  PRINT : PRINT"DISK OPERATIONS
  471. 5540  PRINT"s   Save the current parameters, the associated picture, and a comment string 
  472. 5550  PRINT"to disk.
  473. 5560  PRINT"l   Load something you saved before to disk.
  474. 5570  PRINT : PRINT"COMMENTS
  475. 5580  PRINT"e   Enter a comment or edit a previous version.  In addition to numerical data 
  476. 5590  PRINT"about a picture, you can save this text to disk.
  477. 5600  PRINT"t   Display the text of your comment.  It will appear right under the 
  478. 5610  PRINT"parameters if you press p first.
  479. 5620  PRINT:PRINT"SCREEN APPEARANCE
  480. 5630  PRINT"-   Switch palettes-changes the three colors of the Julia set approximations.
  481. 5640  PRINT"0-9   New backround color code.
  482. 5650  GOSUB 6200 : IF A$ <> " " THEN GOSUB 6230 : RETURN ' from overview
  483. 5660  GOSUB 6260
  484. 5670  PRINT"BOX MODE
  485. 5680  PRINT"     Enter box mode by pressing b.  Then you can place a flashing box wherever 
  486. 5690  PRINT"you like on the screen and use its coordinates for your next window in a blowup"
  487. 5700  PRINT"of the Julia set picture.
  488. 5710  PRINT"    Pressing h in box mode gives the alphabetical help menu of all the commands"
  489. 5720  PRINT"listed below.
  490. 5730  PRINT"     Initially the arrow keys move the center of the box, but if you press s or ";
  491. 5740  PRINT"r the center will be fixed and you can change the dimensions.  If you press s 
  492. 5750  PRINT"then the arrows separately adjust the width and height.  If you press r, then 
  493. 5760  PRINT"the width and height are changed together, related by a factor f, which you can ";
  494. 5770  PRINT"set.  If you want to go back to moving the center, press c.
  495. 5780  PRINT"     The magnitude of the changes induced by the arrow keys are doubled after 
  496. 5790  PRINT"each time you press +, and halved when you press -.
  497. 5800  PRINT"    You can see the coordinates of your box by pressing w.  If you want the 
  498. 5810  PRINT"current box coordinates to be the coordinates for your next whole window, then 
  499. 5820  PRINT"press a to accept the new window coordinates and leave box mode.  (You could 
  500. 5830  PRINT"then press j to see the blown up Julia set.)
  501. 5840  PRINT"    Instead of pressing a to leave box mode you could press q or k.  Press q to";
  502. 5850  PRINT"quit without changing window parameters.  Pressing k will not change window 
  503. 5860  PRINT"parameters either, but it will leave a nonflashing box in your picture. (This 
  504. 5870  PRINT"is so you can save the picture showing where you plan the next blowup.)
  505. 5880  PRINT"Pressing b again returns you to box mode with the box in the same place on the 
  506. 5890  PRINT"screen.  Then you can press a to accept the new window and j to calculate the 
  507. 5900  PRINT"blown up Julia set.)";   
  508. 5910   GOSUB 6200 : IF A$ <> " " THEN GOSUB 6230 : RETURN ' from overview
  509. 5920  GOSUB 6260
  510. 5930  PRINT"SUGGESTIONS ON CHOOSING PARAMETERS
  511. 5940  PRINT"     If you have a monochrome graphics monitor, initially set all three         iteration limits (i) to be equal.  Later if you want to change the common       number, use the maximum command (m).
  512. 5950  PRINT"     If a Julia set does not entirely lie in the rectangle -2 < x < 2,          -1 < y < 1, then this program will NOT display it correctly.  This will not be aproblem if Im(L) = 0 with any allowed value of Re(L), 0 < Re(L) < 2.  No neat
  513. 5960  PRINT"generalization can be made for Im(L) > 0, but for middle sized values of Re(L), fairly large values of Im(L) can be chosen, as you can see by experiment.
  514. 6100  PRINT : PRINT"DETAILS OF PARAMETER ROUNDING FOR THE ALGORITHM
  515. 6110  PRINT"     The integer arithmetic used in the machine language subroutine gives the 
  516. 6120  PRINT"speed of picture calculation, but there is a tradeoff in resolution.  The x 
  517. 6130  PRINT"coordinate of each pixel must be a multiple of 2^(-14); y, a multip[le of 2^(-
  518. 6140  PRINT"15); Re(L), of 2^(-14); and Im(L), of 2^(-13).  The minimum width of a picture 
  519. 6150  PRINT"therefore is 319 times 2^(-14), approximately .019.  The rounded values for L 
  520. 6160  PRINT"and the x limits are shown when you redisplay the parameters.  
  521. 6170  GOSUB 6200 : IF A$ <> " " THEN GOSUB 6230 : RETURN ' from overview
  522. 6180  CLS : GOTO 5010      ' back to beginning of overview
  523. 6190  ' start get key
  524. 6200  A$ = INKEY$ : IF A$="" THEN 6200 ELSE RETURN  ' from get key
  525. 6210  '
  526. 6220  ' start fix screen at end of overview
  527. 6230  SCREEN 1,0 : COLOR COLR, PAL : RETURN  ' fromfix screen after overview
  528. 6240  '
  529. 6250  ' start clear for next page
  530. 6260  CLS :LOCATE 25,1 : PRINT"PRESS SPACEBAR FOR MORE.  ENTER A COMMAND TO EXIT THE OVERVIEW." : LOCATE 1,1 :RETURN   ' from clearing for next page
  531.